<?php

/**
 * DtSchedule form.
 *
 * @package    DUYTAN
 * @subpackage form
 * @author     Your name here
 * @version    SVN: $Id: sfDoctrineFormTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class DtScheduleForm extends BaseDtScheduleForm
{
  public function configure()
  {
		$this->setWidgets(array(
                'ground_id'               	=> new sfWidgetFormChoice(array('choices' => $this->getGroundCollection())),
                'schedule'                	=> new sfWidgetFormInput(),
				'cost'                		=> new sfWidgetFormInput(),
				'cost_weekend'         		=> new sfWidgetFormInput(),
				'promotion'            		=> new sfWidgetFormInput()
				));
		$this->setValidators(array(
	            'ground_id'               	=>  new sfValidatorChoice(array('choices' => array_keys($this->getGroundCollection()))),
	            'schedule'                	=>  new sfValidatorString(array('required' => false)),
				'cost'                		=>  new sfValidatorInteger(array('required' => false)),
				'cost_weekend'         		=>  new sfValidatorInteger(array('required' => false)),
				'promotion'            		=>  new sfValidatorInteger(array('required' => false))
		));
        $this->widgetSchema->setNameFormat('schedule[%s]');
		$this->widgetSchema->setLabels(array(
				'ground_id'					=> 'Mã số sân',
				'schedule'					=> 'Giờ',
				'cost'						=> 'Giá',
				'cost_weekend'				=> 'Giá cuối tuần',
				'promotion'					=> 'Khuyến mãi',
		));
  }


  private function getGroundCollection()
 {
	$q = Doctrine_Query::create()
			->select('g.id, g.name')
			->from('DtGround g');
	$options = $q->fetchArray();
	$res = array();
	foreach ($options as $option)
		$res[$option['id']] = $option['name'];
	return $res;
 }
}
